package structure.algorithm;
/**
 * 九九乘法表
 * @author fidel
 */
public class MultiplicationTableDemo {
    public static void main(String[] args) {
        // while
        int a = 1;
        while (a <= 9) {
            int b = 1;
            while (b <= a) {
                if (b == a) {
                    System.out.println(a + "*" + b + "=" + a * b);
                } else {
                    System.out.print(a + "*" + b + "=" + a * b +"\t");
                }
                b = b + 1;
            }
            a = a + 1;
        }
        // for
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                if (j == i) {
                    System.out.println(i + "*" + j + "=" + i * j);
                } else {
                    System.out.print(i + "*" + j + "=" + i * j +"\t");
                }
            }
        }
        // do...while
        int x = 1;
        do {
            int y = 1;
            do {
                if (y == x) {
                    System.out.println(x + "*" + y + "=" + x * y);
                } else {
                    System.out.print(x + "*" + y + "=" + x * y +"\t");
                }
                y += 1;
            } while (y <= x);
            x += 1;
        } while (x <= 9);
    }
}
